function [ net, output] = create_fit_net(inputs,targets, numHiddenNeurons)
%CREATE_FIT_NET Creates and trains a fitting neural network.
%
%  NET = CREATE_FIT_NET(INPUTS,TARGETS) takes these arguments:
%    INPUTS - RxQ matrix of Q R-element input samples
%    TARGETS - SxQ matrix of Q S-element associated target samples
%  arranged as columns, and returns these results:
%    NET - The trained neural network
%
%  For example, to solve the Simple Fit dataset problem with this function:
%
%    load simplefit_dataset
%    net = create_fit_net(simplefitInputs,simplefitTargets);
%    simplefitOutputs = sim(net,simplefitInputs);
%
%  To reproduce the results you obtained in NFTOOL:
%
%    net = create_fit_net(input_red,output_red);

% Create Network
net = newfit(inputs,targets,numHiddenNeurons);
net.divideParam.trainRatio = 70/100;  % Adjust as desired
net.divideParam.valRatio = 15/100;  % Adjust as desired
net.divideParam.testRatio = 15/100;  % Adjust as desired

% Train and Apply Network
[net,tr] = train(net,inputs,targets);
[ row_count, column_count ] = size(inputs);
[net_outputs,Final_input_delay ,Final_layer_delay ,Errors, performance] = sim(net,inputs,zeros(row_count,0),zeros(row_count,0),targets);

%retrieving performance
%output = sum(abs(Errors));
%output = performance;
%retrieving mse
output = mse(Errors);

double_check = net_outputs + Errors;

% Plot
%plotperf(tr)
%plotfit(net,inputs,targets)
%plotregression(targets,outputs)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotfit(targets,outputs)
%figure, plotregression(targets,outputs)
%figure, ploterrhist(errors)
